home *** CD-ROM | disk | FTP | other *** search
- #
- # cmdtrace.test
- #
- # Tests for the cmdtrace command.
- #---------------------------------------------------------------------------
- # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies. Karl Lehenbauer and
- # Mark Diekhans make no representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
- #------------------------------------------------------------------------------
- # $Id: cmdtrace.test,v 2.0 1992/10/16 04:49:40 markd Rel $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] == ""} then {source testlib.tcl}
-
- #
- # Proc to do something to trace.
- #
- proc DoStuff {} {
- set foo [replicate "-TheString-" 10]
- set baz $foo
- set wap 1
- if {$wap} {
- set wap 0
- } else {
- set wap 1
- }
- }
- proc DoStuff1 {} {DoStuff}
- proc DoStuff2 {} {DoStuff1}
- proc DoStuff3 {} {DoStuff2}
- proc DoStuff4 {} {DoStuff3}
-
- #
- # Proc to retrieve the output of a trace. It determines the level of the first
- # line. This is used to strip off level number and identation from each line.
- # so that all lines will be indented the same amount. It also closes the
- # trace file.
-
- proc GetTrace {cmdtraceFH} {
- set result {}
- seek $cmdtraceFH 0 start
- if {([gets $cmdtraceFH line] < 2) ||
- ([scan $line "%d" level] != 1)} {
- error "*Incorrect format for first line of the trace*"
- }
- set nuke [expr ($level*2)+3]
- seek $cmdtraceFH 0 start
- while {[gets $cmdtraceFH line] >= 0} {
- set linelen [clength $line]
- if {$linelen == 0} {
- continue}
- if {$linelen < $nuke} {
- error "invalid trace line: `$line'"}
- append result "[crange $line $nuke end]\n"
- }
- close $cmdtraceFH
- return $result
- }
-
- Test cmdtrace-1.1 {command trace: evaluated, truncated} {
- set cmdtraceFH [open CMDTRACE.OUT w+]
- cmdtrace on $cmdtraceFH
- DoStuff4
- cmdtrace off
- GetTrace $cmdtraceFH
- } 0 {DoStuff4
- DoStuff3
- DoStuff2
- DoStuff1
- DoStuff
- replicate -TheString- 10
- set foo -TheString--TheString--TheString--TheStr...
- set baz -TheString--TheString--TheString--TheStr...
- set wap 1
- if $wap {\n set wap 0\n } else {\n set wap 1\n }
- set wap 0
- cmdtrace off
- }
-
- Test cmdtrace-1.2 {command trace: not evaluated, truncated} {
- set cmdtraceFH [open CMDTRACE.OUT w+]
- cmdtrace on $cmdtraceFH noeval flush
- DoStuff4
- cmdtrace off
- GetTrace $cmdtraceFH
- } 0 "DoStuff4
- DoStuff3
- DoStuff2
- DoStuff1
- DoStuff
- replicate \"-TheString-\" 10
- set foo \[replicate \"-TheString-\" 10\]
- set baz \$foo
- set wap 1
- if {\$wap} {\\n set wap 0\\n } else {\\n set wap 1...
- set wap 0
- cmdtrace off
- "
-
- Test cmdtrace-1.3 {command trace: evaluated, not truncated} {
- set cmdtraceFH [open CMDTRACE.OUT w+]
- cmdtrace on $cmdtraceFH notruncate
- DoStuff4
- cmdtrace off
- GetTrace $cmdtraceFH
- } 0 {DoStuff4
- DoStuff3
- DoStuff2
- DoStuff1
- DoStuff
- replicate -TheString- 10
- set foo -TheString--TheString--TheString--TheString--TheString--TheString--TheString--TheString--TheString--TheString-
- set baz -TheString--TheString--TheString--TheString--TheString--TheString--TheString--TheString--TheString--TheString-
- set wap 1
- if $wap {\n set wap 0\n } else {\n set wap 1\n }
- set wap 0
- cmdtrace off
- }
-
- Test cmdtrace-1.4 {command trace: not evaluated, not truncated} {
- set cmdtraceFH [open CMDTRACE.OUT w+]
- cmdtrace on $cmdtraceFH notruncate noeval flush
- DoStuff4
- cmdtrace off
- GetTrace $cmdtraceFH
- } 0 {DoStuff4
- DoStuff3
- DoStuff2
- DoStuff1
- DoStuff
- replicate "-TheString-" 10
- set foo [replicate "-TheString-" 10]
- set baz $foo
- set wap 1
- if {$wap} {\n set wap 0\n } else {\n set wap 1\n }
- set wap 0
- cmdtrace off
- }
-
- Test cmdtrace-2.1 {command trace argument error checking} {
- cmdtrace foo
- } 1 {expected integer but got "foo"}
-
- Test cmdtrace-2.2 {command trace argument error checking} {
- cmdtrace on foo
- } 1 {invalid option: expected one of "noeval", "notruncate", "procs", "flush" or a file handle}
-
- Test cmdtrace-2.3 {command trace argument error checking} {
- catch {close file20}
- cmdtrace on file20
- } 1 {file "file20" isn't open}
-
- unlink CMDTRACE.OUT
-